const express = require('express');
const path = require('path');
const cookieparser = require('cookie-parser');
const multer = require('multer');
const bodyParser = require('body-parser');
const base = require(path.join(__dirname, './base'));
const menuService = require(path.join(__dirname, './../service/menuservice'));
let router = express.Router();

router.get('/getmenu', async function (req, res) {
    let param = req.query;
    let data = await menuService.queryMenuList(param).catch(
        err => {
            console.log(JSON.stringify(err))
        });
    base.send(res,data);
})

router.get('/get', async function (req, res) {
    let param = req.query;
    let data = await menuService.queryMenu(param).catch(
        err => {
            console.log(JSON.stringify(err))
        });
    base.send(res,data);
})

router.post('/save', bodyParser.json(), async function (req, res) {
    let param = req.body;
    // console.log(req);
    // console.log("params:"+JSON.stringify(req.params));
    // console.log("body:"+JSON.stringify(req.body));
    // console.log("query:"+JSON.stringify(req.query));
    let data = await menuService.saveMenu(param).catch(
        err => {
            console.log(JSON.stringify(err))
        });
    base.send(res,data);
});

router.put('/update',bodyParser.json(), async function (req, res) {
    let param = req.body;
    let data = await menuService.updateMenu(param).catch(
        err => {
            console.log(JSON.stringify(err))
        });
    base.send(res,data);
});

router.delete('/delete', async function (req, res) {
    let param = req.query;
    let data = await menuService.deleteMenu(param).catch(
        err => {
            console.log(JSON.stringify(err))
        });
    base.send(res,data);
});

//导出该路由
module.exports = router;